<?php

class Register_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function saveUser($data) {

        $this->db->set($data);
        $this->db->insert('url_users');
        $id = $this->db->insert_id();
        $this->result = $this->db->insert_id() ; 
		return $this->result ;

        
    }

    function getUser() {
        $this->db->select('*');
        $this->db->from('url_users');
        $this->db->order_by("id", "asc");
        $query = $this->db->get();
        return $query->result();
    }

    function DeleteUser($id) {

        $id = $_GET['id'];
        $this->db->delete('url_users', array('id' => $id));
        $location = 'location:' . base_url() . "user?msg=SuccessFully Deleted id $id";
        header($location);
    }

    function editUser() {
        $id = $_GET['id'];
        $this->db->select('*');
        $this->db->where('id', $id);
        $query = $this->db->get('url_users');
        return $query->result();
    }

    function updateUser($data) {
        $id = $this->input->post('id');
        $data = array(
            'name' => $data['name'],
            'username' => $data['username'],
            'email' => $data['email'],
            'password' => $data['password'],
          //  'create_time' => $data['Y-m-d'],
        );
        $this->db->where('id', $id);
        $this->db->update('url_users', $data);

        $location = 'location:' . base_url() . "user?msg=SuccessFully Saved on id $id";

        header($location);
        return;
    }

    function check_user($name) {
        $query = $this->db->get_where('url_users', array('username' => $name));
        $uresult = $query->result();
        return $uresult;
    }
   
    function setStatus($post)
   {
		$data = array(
			'status' => $post['status']);
		 
		$this->db->where('id', $post['id']);
		$this->db->update('url_users', $data); 
                //  echo $this->db->last_query();
                       
		return true; 
   } 
 function check_email($str)
	{
		$this->db->select('email');
		$this->db->from('url_users');
		$this->db->where('email', $str);
		
		$count = $this->db->count_all_results();
		
		if ($count > 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

?>
